package com.example.tioClient.listener;

import org.tio.core.ChannelContext;
import org.tio.core.DefaultAioListener;
import org.tio.core.intf.Packet;

public class TioClientAioListener extends DefaultAioListener {


    private ClientListenerBase listenerBase;

    public TioClientAioListener(ClientListenerBase listenerBase){

        this.listenerBase=listenerBase;
    }


    /**
     *
     * @param channelContext
     * @param isConnected
     * @param isReconnect
     * @author tanyaowu
     */
    @Override
    public void onAfterConnected(ChannelContext channelContext, boolean isConnected, boolean isReconnect) {
        try {
            listenerBase.onAfterConnected( channelContext,  isConnected,  isReconnect);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     *
     * @param channelContext
     * @param packet
     * @param packetSize
     * @author tanyaowu
     */
    @Override
    public void onAfterDecoded(ChannelContext channelContext, Packet packet, int packetSize) {
        try {
            listenerBase.onAfterDecoded( channelContext,  packet,  packetSize);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     *
     * @param channelContext
     * @param packet
     * @param isSentSuccess
     * @throws Exception
     * @author tanyaowu
     */
    @Override
    public void onAfterSent(ChannelContext channelContext, Packet packet, boolean isSentSuccess) throws Exception {

        listenerBase.onAfterSent( channelContext,  packet,  isSentSuccess);

    }

    @Override
    public void onBeforeClose(ChannelContext channelContext, Throwable throwable, String remark, boolean isRemove) {
        try {
            listenerBase.onBeforeClose( channelContext,  throwable,  remark,  isRemove);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void onAfterHandled(ChannelContext channelContext, Packet packet, long cost) throws Exception {
        listenerBase.onAfterHandled( channelContext,  packet,  cost);

    }

    @Override
    public void onAfterReceivedBytes(ChannelContext channelContext, int receivedBytes) throws Exception {
        listenerBase.onAfterReceivedBytes( channelContext,  receivedBytes);
    }

    @Override
    public boolean onHeartbeatTimeout(ChannelContext channelContext, Long interval, int heartbeatTimeoutCount) {

        return listenerBase.onHeartbeatTimeout( channelContext,  interval,  heartbeatTimeoutCount);
    }





}
